package com.niodata.dt.fs;

import com.google.common.base.Strings;
import java.io.IOException;
import java.util.Map;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem;

public class S3FileSystemBuilder implements FileSystemBuilder {

  public FileSystem createFileSystem(String user, Map<String, String> conf)
        throws IOException {
    Configuration config = new Configuration();
    //"s3a://dptest"
    String bucket = conf.get("fs.s3a.bucket");
    //config.set
    config.set("fs.defaultFS", "s3a://" + bucket);
    config.setClass("fs.s3a.impl", DpS3AFileSystem.class, FileSystem.class);
    for (String key : conf.keySet()) {
      String value = conf.get(key);
      if (!Strings.isNullOrEmpty(value)) {
        config.set(key, value);
      }
    }
    FileSystem fs = FileSystem.get(config);
    return fs;
  }
}
